import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

import org.puresilk.android.util.MultiPartForm;

public class MPFTest {
	private static final String url = "http://mobilitytest.rlsworx.com/Mobility/go.mbl?action=HelloMobility";
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		MultiPartForm mpf = new MultiPartForm();
		
		try {
			mpf.addField("action","test.Action");
			mpf.addField("FName", "David");
			mpf.addField("LName","Connell");
			
			mpf.addFile("DragonDrop_sm.jpg");
			
			System.out.println("## Stat ##");
		    System.out.println(mpf.getContentSize());

		    System.out.println("## Dump ##");
		    System.out.println(mpf.dump());

		    System.out.println("## Render ##");
		    byte [] data = mpf.render();
	
		    HttpURLConnection uc = (HttpURLConnection)new URL(url).openConnection();
		    uc.setRequestMethod("POST");
		    uc.setDoOutput(true);
			uc.setRequestProperty("Content-Type", mpf.getContentType());
			uc.setRequestProperty("Content-Length", String.valueOf(mpf.getContentSize()));
			
			// send output
			uc.connect();
			OutputStream os = uc.getOutputStream();
			mpf.write(os, null);
			
		    os.close();

		    int bufsz = 1024 * 1024 * 10;
		    byte [] buffer = new byte [bufsz];
			InputStream isr = uc.getInputStream();
			int read = isr.read(buffer,0,bufsz);
			isr.close();	
		}
		catch(Exception ex){
			ex.printStackTrace();
		}

	}

}
